import NProgress from 'nprogress' // Progress 进度条
import 'nprogress/nprogress.css' // Progress 进度条样式

import { getToken } from 'utils/auth' // 验权


export function routerBeforeEach (to, from, next) {
    if (document.querySelector('.app-main')){
        document.querySelector('.app-main').scrollTop = 0;
    }
// console.log(to)
	NProgress.start()

    if (getToken()) {

        next()

    } else {

        if (to.meta.notNeedLogin === true) {
            next()
        } else {
            location.href = "user.html#/login"
            // next()
            NProgress.done()
        }
    }
}

export function routerAfterEach (route) {

	NProgress.done() // 结束Progress
    
    let title = route.name || "";

    window.document.title = title;
}




